﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Modules/ReconSite.Master" AutoEventWireup="true" CodeBehind="MatchInvoice.aspx.cs" Inherits="Recon.Portal.WebUI.MatchInvoice" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleHolder" runat="server">
    <title>Match Invoices</title>
</asp:Content>

<asp:Content ID="BodyContent" ContentPlaceHolderID="BodyHolder" runat="server">
    <div>
        <hr />
        <div>
            Select Remitter For Matching :
            <asp:DropDownList ID="ddlRemitter" runat="server" AutoPostBack="true" Width="300"
                OnSelectedIndexChanged="ddlRemitter_SelectedIndexChanged">
            </asp:DropDownList>
        </div>
    </div>

    <asp:UpdatePanel ID="upUnmatchedLists" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <div class="formDiv" id="formMatchDiv">
                <table cellspacing="1" cellpadding="1" border="0" width="100%">
                    <tr>
                        <td colspan="5">
                            <asp:Label ID="lblInvoiceList" runat="server" Text="Invoice List:" CssClass="lable" />
                            <div style="height: 380px; width: 600px; overflow: auto;">
                                <asp:GridView ID="grdInvoice" runat="server" AutoGenerateColumns="False" Width="600"
                                    HeaderStyle-BackColor="#222222" HeaderStyle-ForeColor="#6f788f" ForeColor="#333333"
                                    HeaderStyle-Font-Bold="false" OnRowDataBound="grdInvoice_RowDataBound">
                                    <EmptyDataTemplate>
                                        <asp:Label ID="lblNoRows" runat="server" Text="There are no Invoices to be matched." />
                                    </EmptyDataTemplate>
                                    <Columns>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                                <input id="SelectAllCheckBox" type="checkbox" name="SelectAllCheckBox" style="azimuth: left; left: 0px;" onclick="javascript: SelectAllInvoice(this)">
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:Literal ID="ltlInvoiceUniqueID" runat="server" Text='<%# Eval("InvoiceID") %>' Visible="false" />
                                                <input id="chkSelect" type="checkbox" name="chk" runat="server" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField HeaderText="Invoice No" DataField="InvoiceNumber" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Date" DataField="InvoiceDate" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Remitter" DataField="RemitterName" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Amount" DataField="Amount" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Reconciled Amount" DataField="ReconciledAmount" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Remaining Amount" DataField="AmountToReconcile" HeaderStyle-Font-Bold="false" />
                                    </Columns>
                                    <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f" />
                                </asp:GridView>
                            </div>
                        </td>
                        <td colspan="5" align="left">
                            <asp:Label ID="lblStatementList" runat="server" Text="Statement List:" CssClass="lable" />
                            <div style="height: 380px; width: 700px; overflow: auto;">
                                <asp:GridView ID="grdStatement" runat="server" AutoGenerateColumns="false" Width="600"
                                    HeaderStyle-BackColor="silver" HeaderStyle-ForeColor="#6f788f" ForeColor="#333333"
                                    HeaderStyle-Font-Bold="false" OnRowDataBound="grdStatement_RowDataBound">
                                    <EmptyDataTemplate>
                                        <asp:Label ID="lblNoRows" runat="server" Text="There are no Statements to be matched." />
                                    </EmptyDataTemplate>
                                    <Columns>
                                        <asp:TemplateField>
                                            <HeaderTemplate>
                                                <input id="SelectAllCheckBox" type="checkbox" name="SelectAllCheckBox" onclick="javascript: SelectAllStatement(this)">
                                            </HeaderTemplate>
                                            <ItemTemplate>
                                                <asp:Literal ID="ltlStatementUniqueID" runat="server" Text='<%# Eval("StatementID") %>' Visible="false" />
                                                <input id="chkSelect" type="checkbox" name="chk" runat="server" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                        <asp:BoundField HeaderText="PaymentRef#/Cheque#" DataField="referenceNumber" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Date" DataField="valueDate" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Narration1" DataField="narration1" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Amount" DataField="amount" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Reconciled Amount" DataField="ReconciledAmount" HeaderStyle-Font-Bold="false" />
                                        <asp:BoundField HeaderText="Remaining Amount" DataField="AmountToReconcile" HeaderStyle-Font-Bold="false" />
                                    </Columns>
                                    <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f" />
                                </asp:GridView>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <div>
                <div id="divButtons" runat="server">
                    <asp:Button ID="btnManualMatch" runat="server" Text="Mark Manual Match" OnClick="btnManualMatch_Click"
                        BorderStyle="Groove" BackColor="#101e45" ForeColor="#FFFFFF" />
                    &nbsp;<asp:Button ID="btnAutoMatching" runat="server" Text="Auto Matching"
                        OnClick="btnAutoMatching_Click" />
                    &nbsp;<asp:Button ID="btnSendToRemitter" runat="server" Text="Send to Remitter" OnClick="btnSendToRemitter_Click" />
                </div>

                <div id="pnlMatchList" runat="server" class="pnlMatchList">
                    <span style="azimuth: center;">
                        <asp:Label ID="lblMatchList" runat="server" Text="List of Selected Invoice:Statement Matches:" CssClass="lable" />
                        <div style="height: 400px; width: 850px; overflow: auto; azimuth: center;">
                            <asp:GridView ID="grdMatchList" runat="server" AutoGenerateColumns="false" CssClass="formDiv"
                                HeaderStyle-BackColor="#555555" HeaderStyle-ForeColor="#6f788f"
                                HeaderStyle-Font-Bold="false" OnRowDataBound="grdMatchList_RowDataBound">
                                <EmptyDataTemplate>
                                    <asp:Label ID="lblNoRows" runat="server" Text="There are no Invoice:Statement match selections." />
                                </EmptyDataTemplate>
                                <Columns>
                                    <asp:TemplateField HeaderText="" Visible="false">
                                        <ItemTemplate>
                                            <asp:Literal ID="ltlInvoiceUniqueID" runat="server" Text='<%# Eval("InvoiceUniqueID") %>'
                                                Visible="false" />
                                            <asp:Literal ID="ltlStatementUniqueID" runat="server" Text='<%# Eval("StatementUniqueID") %>'
                                                Visible="false" />
                                            <asp:Literal ID="ltlIsPartialInvoiceMatch" runat="server" Text='<%# Eval("IsPartialInvoiceMatch") %>'
                                                Visible="false" />
                                            <asp:Literal ID="ltlIsPartialStatementMatch" runat="server" Text='<%# Eval("IsPartialStatementMatch") %>'
                                                Visible="false" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField HeaderText="Invoice No" DataField="InvoiceNumber" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Date" DataField="InvoiceDate" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Remitter" DataField="RemitterName" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Amount" DataField="InvoiceAmount" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="PaymentRef#/Cheque#" DataField="ReferenceNumber" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Date" DataField="ValueDate" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Narration1" DataField="Narration1" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Amount" DataField="StatementAmount" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Invoice Amount to Reconcile" DataField="InvoiceAmountToReconcile" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Statement Amount to Reconcile" DataField="StatementAmountToReconcile" HeaderStyle-Font-Bold="false" />
                                </Columns>
                                <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f" />
                            </asp:GridView>
                        </div>
                    </span>
                    <div class="formDiv" style="width: 22%; border: 0.1em solid #FFFFFF; background: #FFFFFF;">
                        <asp:Button ID="btnConfirmMatches" runat="server" Text="Confirm Matches" OnClick="btnConfirmMatches_Click" />
                        <asp:Button ID="btnCancelMatches" runat="server" Text="Cancel" OnClick="btnCancelMatches_Click" />
                    </div>
                </div>
                <div style="display: none">
                    <asp:Button ID="btnManualPopup" runat="server" />
                </div>

                <ajax:ModalPopupExtender ID="ManualMatchConfirmationPopup" runat="server" PopupControlID="pnlMatchList"
                    TargetControlID="btnManualPopup" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowScroll">
                </ajax:ModalPopupExtender>

                <div id="pnlRemitterList" runat="server" class="pnlMatchList">
                    <span style="azimuth: center;">
                        <asp:Label ID="Label1" runat="server" Text="List of Selected Invoices to be sent to Remitter:" CssClass="lable" />
                        <div style="height: 400px; width: 850px; overflow: auto; azimuth: center;">
                            <asp:GridView ID="grdRemitter" runat="server" AutoGenerateColumns="false" CssClass="formDiv"
                                HeaderStyle-BackColor="#555555" HeaderStyle-ForeColor="#6f788f"
                                HeaderStyle-Font-Bold="false" OnRowDataBound="grdRemitter_RowDataBound">
                                <EmptyDataTemplate>
                                    <asp:Label ID="lblNoRows" runat="server" Text="There are no Invoice selections to be sent to Remitter." />
                                </EmptyDataTemplate>
                                <Columns>
                                    <asp:TemplateField HeaderText="" Visible="false">
                                        <ItemTemplate>
                                            <asp:Literal ID="ltlInvoiceUniqueID" runat="server" Text='<%# Eval("InvoiceID") %>'
                                                Visible="false" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:BoundField HeaderText="Invoice No" DataField="InvoiceNumber" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Date" DataField="InvoiceDate" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Remitter" DataField="RemitterName" HeaderStyle-Font-Bold="false" />
                                    <asp:BoundField HeaderText="Amount" DataField="Amount" HeaderStyle-Font-Bold="false" />
                                </Columns>
                                <HeaderStyle BackColor="silver" Font-Bold="false" ForeColor="#6f788f" />
                            </asp:GridView>
                        </div>
                    </span>
                    <div class="formDiv" style="width: 22%; border: 0.1em solid #FFFFFF; background: #FFFFFF;">
                        <asp:Button ID="btnConfirmRemitter" runat="server" Text="Confirm"
                            OnClick="btnConfirmRemitter_Click" />
                        <asp:Button ID="btnCancelRemitter" runat="server" Text="Cancel"
                            OnClick="btnCancelRemitter_Click" />
                    </div>
                </div>
                <div style="display: none">
                    <asp:Button ID="btnRemitterPopup" runat="server" />
                </div>

                <ajax:ModalPopupExtender ID="RemitterConfirmationPopup" runat="server" PopupControlID="pnlRemitterList"
                    TargetControlID="btnRemitterPopup" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowScroll">
                </ajax:ModalPopupExtender>

                <div id="pnlAutoMatch" runat="server" class="pnlMatchList">
                    <span style="azimuth: center;">
                        <div id="Div5" class="formDiv" runat="server">
                            <center>
                                <asp:Label ID="lblAutoMatch" runat="server" CssClass="lable" />
                            </center>
                        </div>
                    </span>
                    <div class="formDiv" style="width: 30%;">
                        <center>
                            <asp:Button ID="btnAutoMatchok" runat="server" Text="OK"
                                CausesValidation="False" OnClick="btnAutoMatchok_Click" />
                        </center>
                    </div>
                </div>
                <div style="display: none">
                    <asp:Button ID="btnAutoMatchPopup" runat="server" />
                </div>
                <ajax:ModalPopupExtender ID="btnAutoMatchClickPopup" runat="server" PopupControlID="pnlAutoMatch"
                    TargetControlID="btnAutoMatchPopup" BackgroundCssClass="modalBackground" RepositionMode="RepositionOnWindowScroll" OkControlID="btnAutoMatchok">
                </ajax:ModalPopupExtender>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

    <script type="text/javascript">
        function SelectAllStatement(CheckBoxControl) {
            if (CheckBoxControl.checked == true) {
                var i;
                for (i = 0; i < document.forms[0].elements.length; i++) {
                    if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('grdStatement') > -1)) {
                        document.forms[0].elements[i].checked = true;
                    }
                }
            }
            else {
                var i;
                for (i = 0; i < document.forms[0].elements.length; i++) {
                    if ((document.forms[0].elements[i].type == 'checkbox') &&
                    (document.forms[0].elements[i].name.indexOf('grdStatement') > -1)) {
                        document.forms[0].elements[i].checked = false;
                    }
                }
            }
        }

        function SelectAllInvoice(CheckBoxControl) {
            if (CheckBoxControl.checked == true) {
                var i;
                for (i = 0; i < document.forms[0].elements.length; i++) {
                    if ((document.forms[0].elements[i].type == 'checkbox') && (document.forms[0].elements[i].name.indexOf('grdInvoice') > -1)) {
                        document.forms[0].elements[i].checked = true;
                    }
                }
            }
            else {
                var i;
                for (i = 0; i < document.forms[0].elements.length; i++) {
                    if ((document.forms[0].elements[i].type == 'checkbox') &&
                    (document.forms[0].elements[i].name.indexOf('grdInvoice') > -1)) {
                        document.forms[0].elements[i].checked = false;
                    }
                }
            }
        }
    </script>
</asp:Content>
